package com.shujia.reducetask;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.HashMap;

public class ReduceTask {
    //将map得到结果合并，真实的mr中reduce默认只有一个  hodoop/out/Demo3
    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new FileReader("hodoop/out"));
        BufferedWriter bw = new BufferedWriter(new FileWriter("hodoop/out/Demo1"));
        HashMap<String, Long> map = new HashMap<>();
        String line = null;
        try {
            while ((line = br.readLine()) != null) {
                String[] s = line.split("");
                String clazz = s[0];
                Integer Number = Integer.valueOf(s[1]);
                if (map.containsKey(clazz)) {
                    map.put(clazz, map.get(clazz) + Number);
                } else {
                    map.put(clazz, Long.valueOf(Number));
                }
            }

        } catch (Exception e){
            e.printStackTrace();
        }
    }
}
